package property;

import com.gitee.feizns.dynamic.bean.Prop;
import com.gitee.feizns.dynamic.bean.PropIterable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

/**
 * @author feizns
 * @since 2019/6/16 0016
 */
public class EachPropDemo {

    public static void main(String[] args) {

        Admin admin = new Admin("firstName", "lastName");

        for (Prop<Object, Admin> prop : admin) {
            print(prop);
        }

        //属性名=firstName  是否可读=false      是否可写=true       值=null
        //属性名=lastName   是否可读=true       是否可写=true       值=lastName
        //属性名=class      是否可读=true       是否可写=false      值=class property.EachPropDemo$Admin

        // java 8

        admin.forEach(EachPropDemo::print);

    }

    private static void print(Prop<Object, ?> prop) {
        System.out.printf("属性名=%-10s 是否可读=%-10s 是否可写=%-10s 值=%-10s\n", prop.name(), prop.isReadable(), prop.isWritable(), prop.val());
    }

    @Setter
    @AllArgsConstructor
    public static class Admin implements PropIterable<Admin> {

        private String firstName;

        @Getter
        private String lastName;

    }

}
